﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using InvoiceChecking.Data;
using InvoiceChecking.Settings.BusinessLayer;
using Microsoft.Reporting.WebForms;

public partial class Admin_ReportCheck : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            tb_FromDate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
            tb_ToDate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
            btn_Refresh_Click(null, null);
        }
    }
    protected void btn_Refresh_Click(object sender, EventArgs eventArgs)
    {
        Invoices.TitleDataTable dsTitle = new Invoices.TitleDataTable();
        HttpCookie conCookie = Request.Cookies["ICConnectionString"];
        if (conCookie != null)
        {
            //ServiceFacade.SettingsHelper.CheckInvoicesTitle = "THE DAILY INVOICES CHECKING REPORT";
            dsTitle.AddTitleRow(ServiceFacade.SettingsHelper.CheckInvoicesTitle, conCookie.Value);
            SqlCommand cmd = new SqlCommand("ICReport_CheckInvoices");
            cmd.CommandType=CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@FromDate", DateTime.Parse(tb_FromDate.Text + " 00:00:00"));
            cmd.Parameters.AddWithValue("@ToDate", DateTime.Parse(tb_ToDate.Text + " 23:59:59"));
            DataSet ds = DataRepository.Provider.ExecuteDataSet(cmd);
            List<ReportParameter> parameters=new List<ReportParameter>();
            parameters.Add(new ReportParameter("FromDate", tb_FromDate.Text + " 00:00:00"));
            parameters.Add(new ReportParameter("ToDate", tb_ToDate.Text + " 23:59:59"));
            ReportViewer1.LocalReport.SetParameters(parameters);
            ReportViewer1.LocalReport.DataSources["Invoices_Title"].Value = dsTitle;
            ReportViewer1.LocalReport.DataSources["Invoices_Check"].Value = ds.Tables[0];
            //ReportViewer1.LocalReport.DataSources["Invoices_CheckSum"].Value = ds.Tables[1];
            ReportViewer1.DataBind();
        }
    }
}

